1 module unde.games.dizzy.omega.animations.sky_zaks; 2 3 import derelict.opengl3.gl; 4 import derelict.sdl2.mixer; 5 import std.conv; 6 import std.math; 7 import std.stdio; 8 import unde.games.object; 9 import unde.games.renderer; 10 import unde.global_state; 11 12 class SkyZaks:StaticGameObject 13 { 14 StaticGameObject the_hero; 15 16 Mix_Chunk *laugh; 17 18 this(MainGameObject root, StaticGameObject hero) 19 { 20 frame = -1; 21 the_hero = hero; 22 23 models["zaks-face"] = root.models["zaks-face"]; 24 25 laugh = Mix_LoadWAV("sounds/zaks-laugh.wav"); 26 if(!laugh) { 27 writefln("Mix_LoadWAV 'sounds/zaks-laugh.wav': %s", Mix_GetError().to!(string)()); 28 } 29 super(root); 30 } 31 32 override void draw(GlobalState gs) 33 { 34 float f = 0.0; 35 if (frame >= 0) 36 { 37 f = root.frame - frame; 38 } 39 40 glPushMatrix(); 41 if (f <= 0.0) {} 42 else if (f <= 100.0) 43 { 44 glTranslatef(32.6, 20.0 - (20.0-3.1)*f/100.0, 2.0); 45 recursive_render(gs, models["zaks-face"]); 46 } 47 else if (f <= 500.0) 48 { 49 glTranslatef(32.6, 3.1 + sin((f-100.0)/50), 2.0); 50 recursive_render(gs, models["zaks-face"]); 51 } 52 else if (f <= 600.0) 53 { 54 glTranslatef(32.6, 3.1 + (20.0-3.1)*(f-500.0)/100.0, 2.0); 55 recursive_render(gs, models["zaks-face"]); 56 } 57 else {} 58 glPopMatrix(); 59 } 60 61 override bool tick(GlobalState gs) 62 { 63 if (frame >= 0 && root.frame - frame == 100) 64 { 65 if(laugh && Mix_PlayChannel(2, laugh, 0)==-1) 66 { 67 writefln("Mix_PlayChannel laugh: %s\n", 68 Mix_GetError().to!(string)()); 69 } 70 } 71 72 if (frame < 0 && the_hero.x > 37.6) 73 { 74 frame = root.frame; 75 } 76 return true; 77 } 78 79 override void load(string[string] s) 80 { 81 if ("sky-zaks-frame" in s) 82 frame = s["sky-zaks-frame"].to!(long); 83 else 84 frame = -1; 85 } 86 87 override void save(ref string[string] s) 88 { 89 if (frame >= 0) 90 s["sky-zaks-frame"] = frame.to!(string); 91 } 92 }